angular.module('Controller')
.directive('nrHomePcBanner',[()->
            return {
            restrict:'E'
            scope : {
                banners : '=banners'
            }
            replace:true
            templateUrl:'templates/home-pc-banner/home-pc-banner.html'
            controller:'homePcBannerCtrl'
            }
        ])

.controller 'homePcBannerCtrl',($scope,$localStorage)->
    console.log "homePcBannerCtrl"
    homeSwiper=undefined
    loadHomeSwiper=()->
        console.log "loadHomeSwiper"
        homeSwiper = new Swiper('.pc-swiper-container', {
            pagination: '.swiper-pagination'
            paginationClickable: true
            autoplay : 10000
            speed:1000
            onInit: (swiper)->
                swiperAnimateCache(swiper)
                swiperAnimate(swiper)
            onSlideChangeEnd: (swiper)->
                console.log "onSlideChangeEnd"
                swiperAnimate(swiper)
        });
    _.defer(()->
        loadHomeSwiper()
    )
    bannerAnimation = ->
        $('#home-pc-banner-view').mouseenter ->
            thisPX = $(this).offset().left
            thisPY = $(this).offset().top
            boxWidth = $(this).outerWidth()
            boxHeight = $(this).outerHeight()
            $(this).addClass 'threeD'
            $('.threeD').mousemove (event) ->
                mouseX = event.pageX - thisPX
                mouseY = event.pageY - thisPY
                X = undefined
                Y = undefined
                if mouseX > boxWidth / 2
                    X = mouseX - (boxWidth / 2)
                else
                    X = mouseX - (boxWidth / 2)
                if mouseY > boxHeight / 2
                    Y = boxHeight / 2 - mouseY
                else
                    Y = boxHeight / 2 - mouseY
                $('.threeD').css '-webkit-transform': 'rotateY(' + X / 50 + 'deg) ' + 'rotateX(' + Y / 50 + 'deg)'
        $('#home-pc-banner-view').mouseleave ->
            $(this).removeClass 'threeD'
            $(this).css '-webkit-transform': 'rotateY(0deg) rotateX(0deg)'
#    _.defer(()->
#        bannerAnimation()
#    )
